package cn.yuanqiao.web.controller.manage;

import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.core.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.core.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;
import cn.yuanqiao.manage.domain.YqdaApplyModel;
import cn.yuanqiao.manage.service.IYqdaApplyModelService;
import com.alibaba.fastjson2.JSONObject;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * applymodelController
 *
 * @author 赵常飞
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/manage/applymodel")
public class YqdaApplyModelController extends BaseController
{
    @Autowired
    private IYqdaApplyModelService yqdaApplyModelService;

    /**
     * 查询applymodel列表
     */
    //@PreAuthorize("@ss.hasPermi('manage:applymodel:list")
    @Log(title = "应用模板获取列表", businessType = BusinessType.SELECT)
    @GetMapping("/list")
    public TableDataInfo list(YqdaApplyModel yqdaApplyModel)
    {
        startPage();
        List<YqdaApplyModel> list = yqdaApplyModelService.selectYqdaApplyModelList(yqdaApplyModel);
        return getDataTable(list);
    }

    /**
     * 导出applymodel列表
     */
    //@PreAuthorize("@ss.hasPermi('manage:applymodel:export")
    @Log(title = "导出应用模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YqdaApplyModel yqdaApplyModel)
    {
        List<YqdaApplyModel> list = yqdaApplyModelService.selectYqdaApplyModelList(yqdaApplyModel);
        ExcelUtil<YqdaApplyModel> util = new ExcelUtil<YqdaApplyModel>(YqdaApplyModel.class);
        util.exportExcel(response, list, "applymodel数据");
    }

    /**
     * 获取applymodel详细信息
     */
    //@PreAuthorize("@ss.hasPermi('manage:applymodel:query")
    @Log(title = "获取应用模板详细信息", businessType = BusinessType.SELECT)
    @GetMapping(value = "/{menuId}/{categoryId}")
    public AjaxResult getInfo(@PathVariable("menuId") Long menuId, @PathVariable("categoryId") Long categoryId)
    {
        return success(yqdaApplyModelService.selectYqdaApplyModelById(menuId,categoryId));
    }

    /**
     * 新增applymodel
     */
    //@PreAuthorize("@ss.hasPermi('manage:applymodel:add")
    @Log(title = "新增应用模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YqdaApplyModel yqdaApplyModel)
    {
        return toAjax(yqdaApplyModelService.insertYqdaApplyModel(yqdaApplyModel));
    }

    /**
     * 修改applymodel
     */
    //@PreAuthorize("@ss.hasPermi('manage:applymodel:edit")
    @Log(title = "修改应用模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YqdaApplyModel yqdaApplyModel)
    {
        return toAjax(yqdaApplyModelService.updateYqdaApplyModel(yqdaApplyModel));
    }

    /**
     * 删除applymodel
     */
    //@PreAuthorize("@ss.hasPermi('manage:applymodel:remove")
    @Log(title = "删除应用模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryId}/{menuId}")
    public AjaxResult remove(@PathVariable Long categoryId, @PathVariable Long menuId)
    {
        return toAjax(yqdaApplyModelService.deleteYqdaApplyModel(categoryId,menuId));
    }

    //@PreAuthorize("@ss.hasPermi('manage:applymodel:clonefield")
    @Log(title = "克隆应用模板", businessType = BusinessType.OTHER)
    @PostMapping("/clonefield")
    public AjaxResult clonefield(@RequestBody JSONObject json)
    {
        return toAjax(yqdaApplyModelService.clonefield(json));
    }

    /**
     * 查询applymodel菜单列表
     */
    //@PreAuthorize("@ss.hasPermi('manage:applymodel:list")
    @Log(title = "查询应用模板菜单", businessType = BusinessType.SELECT)
    @GetMapping("/listmenu")
    public TableDataInfo listmenu(@RequestParam String menuName, @RequestParam Long categoryId)
    {
        startPage();
        //String menuName=json.getString("menuName");
        if("".equals(menuName)||null==menuName||"null".equals(menuName)){
            menuName=null;
        }
        List<Map<String,String>> list = yqdaApplyModelService.selectYqdaApplyModelListmenu(menuName,categoryId);
        return getDataTable(list);
    }

    /**
     * 查询applymodel菜单列表
     */
    //@PreAuthorize("@ss.hasPermi('manage:applymodel:list")
    @Log(title = "查询应用模板菜单", businessType = BusinessType.SELECT)
    @GetMapping("/fieldlist")
    public AjaxResult getfieldlist(@Param("menuId") Long menuId, @Param("categoryId") Long categoryId, @Param("field") String field)
    {
        JSONObject returnjson=new JSONObject();
        returnjson.put("field",yqdaApplyModelService.getfieldlist(menuId,categoryId,field));
        return success(returnjson);
    }

    //@PreAuthorize("@ss.hasPermi('manage:applymodel:list")
    @Log(title = "应用模板获取菜单列表", businessType = BusinessType.SELECT)
    @GetMapping("/menulist")
    public AjaxResult menulist(@RequestBody JSONObject json)
    {
        JSONObject returnjson=new JSONObject();
        returnjson.put("list",yqdaApplyModelService.getmenulist(json));
        return success(returnjson);
    }
    //@PreAuthorize("@ss.hasPermi('manage:applymodel:add")
    @Log(title = "添加应用模板", businessType = BusinessType.INSERT)
    @PostMapping("/addmultiplemenu")
    public AjaxResult addmultiplemenu(@RequestBody JSONObject json)
    {
        return toAjax(yqdaApplyModelService.addmultiplemenu(json));
    }

    @Log(title = "获取菜单", businessType = BusinessType.SELECT)
    @GetMapping("/getmenu/{categoryId}")
    public AjaxResult getmenu(@PathVariable("categoryId") Long categoryId)
    {
        return success(yqdaApplyModelService.getmenu(categoryId));
    }


    @Log(title = "获取菜单", businessType = BusinessType.SELECT)
    @PostMapping("/getmdatalist")
    public AjaxResult getmdatalist(@RequestBody JSONObject json)
    {
        return success(yqdaApplyModelService.getmdatalist(json));
    }

    @Log(title = "删除应用模板", businessType = BusinessType.DELETE)
    @PostMapping("/deletebycatemenu")
    public AjaxResult deletebycatemenu(@RequestBody com.alibaba.fastjson.JSONObject json)
    {
        return toAjax(yqdaApplyModelService.deletebycatemenu(json));
    }
}
